<template>
    <div>
        <h2>医生添加</h2>
        <table class="table-table">
            <tr>
                <td>姓名</td>
                <td>
                    <input type="text" v-model="data.xm">
                </td>
            </tr>
               <tr>
                <td>科室名称</td>
                <td> 
                    <select v-model="data.ksid">
                        <option value="null">请选择</option>
                        <option v-for="m in ks" :value="m.ksid">{{ m.ksmc }}</option>
                    </select>
                </td>
            </tr>
               <tr>
                <td>图片</td>
                <td>
                    <input type="file" @change="tps">
                    <img :src="'https://localhost:7209/'+data.img" style="width: 60px;height: 60px;">
                </td>
            </tr>
               <tr>
                <td>创建日期</td>
                <td>
                    <input type="date" v-model="data.yscjrq">
                </td>
            </tr>
               <tr>
                <td></td>
                <td>
                    <input type="button" value="添加" @click="add">
                </td>
            </tr>
        </table>

    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';



const data=ref({
  "ysid": 0,
  "xm": "",
  "img": "",
  "ksid": null,
  "yscjrq": "2025-05-19T04:10:58.741Z"
})

const ks=ref([{
     "ksid": 1,
    "ksmc": "毛细血管科室",
    "ksrs": "12",
    "ksms": "主要是毛细血管出血",
    "kssc": "",
    "kscjrq": "2025-05-19T02:18:51.5"
}])

onMounted(()=>{
    ksxs();
})
const ksxs=()=>{
    axios.get("https://localhost:7209/api/Houseksxx/xss").then(res=>{
        ks.value=res.data
    })
}
const tps=(a:any)=>{
    var f =a.target.files[0];
    var fs= new FormData
    fs.append("file",f)
 
    if(f.size>1024*1024*2){
        alert("上传图片文件大小不能超过2MB")
        return
    }
    axios.post("https://localhost:7209/api/tp/tps",fs).then(res=>{
        data.value.img=res.data
    })
}


const add=()=>{
    if(data.value.xm==""){
        alert("姓名不能为空");
        return
    }

    axios.post("https://localhost:7209/api/Doteroxxb/ysadd",data.value).then(res=>{
        if(res.data>0){
            alert("添加成功");
            location.href="/ysxs"

        }else{
            alert("添加失败")
        }
    })
}
</script>

<style scoped>

</style>